<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="../css/layui.css" rel="stylesheet">
<script type="text/javascript" src="../layui.all.js"></script>
		<title>...</title>
	
	</head>
	<body>
	<body class="childrenBody">
<form class="layui-form changePwd" id="myform">
	<input type="hidden" id="callId" name="callId" value="${callId }"/>
	<input type="hidden" id="type" name="type" value="${type }"/>
	
	
	<div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div id="divhtml" class="layui-input-block">
      
      <%-- <c:forEach items="${users }" var="user">
      	<input type="checkbox" name="callUserIds" value="${user.id }" title="${user.realName }">
	</c:forEach> --%>
    </div>
  </div>
  
  
	
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="save()">保存</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="parent.close();">关闭</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="../js/common/jquery.min.js"></script>
<script type="text/javascript" src="../js/common/common.js"></script>
<script>


var form;
var layer;
    $(function(){
    	
    	layui.use(['form', 'layedit', 'laydate'], function(){
    		   form = layui.form
    		  ,layer = layui.layer
    		  ,layedit = layui.layedit
    		  ,laydate = layui.laydate;
    		  
    		  form.render();
    	})
    	
    	var html='';
        $.ajax({
            url: '/web_seach/group/getAllDatas',
            
            async:false,
            success: function(data){
            	data=JSON.parse(data);
            	
            	$.each(data.data,function(i,obj){
            		
            		html+='<br/><br/><br/>'+obj.groupName+'<br/>';
            		$.ajax({
                        url: '/web_seach/user/getDatasByGroupId?groupId='+obj.id,
                        async:false,
                        success: function(data1){
                        	data1=JSON.parse(data1);
                        	$.each(data1.data,function(j,obj1){
                        		html+='<input type="checkbox" name="callUserIds" value="'+obj1.id+'" title="'+obj1.realName+'">';
                        	})
                        	
                        	$("#divhtml").html(html);
                        	
                        	form.render();
                        	
                        	var param={};
                        	param.callId = $("#callId").val();
                        	param.type = $("#type").val();
                        	var url = "/web_seach/accControlMap/getUserCheckDatas";
                            $.ajax({
                            	async:false,
                                url: url,
                                data:param,
                                dataType:"json",
                                success: function(data){
                                	
                                    $.each(data.data,function(i,obj){
                                    	$("input[name=callUserIds][value="+obj.callUserId+"]").attr("checked", 'checked');
                                    })
                                    form.render();
                                }
                            });
                        }
                    });
            	})
            	
            	
            }
        });
    	
    	
    	
    	
    	
    })
	function save(){
    	var params = $("#myform").serializeObject(); 
    	
    	if($.isArray(params.callUserIds)){
    		params.callUserIds =params.callUserIds.join(',');
    	}
    	
    	var url = "/web_seach/accControlMap/save";
    	
    	alert("保存成功！");
        parent.layer.closeAll();
        $.ajax({
            url: url,
            data:params,
            success: function(data){
                if(data == 0){
                    alert("保存成功！");
                    parent.layer.closeAll()
                }else{
                    layer.msg("保存失败！");
                }
            }
        });
    }
   

</script>
</body>

</body>


</html>
